package cn.iocoder.yudao.module.service.service.stepform;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

import cn.iocoder.yudao.module.service.controller.admin.stepform.vo.*;
import cn.iocoder.yudao.module.service.dal.dataobject.stepform.StepFormDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.service.dal.mysql.stepform.StepFormMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.service.enums.ErrorCodeConstants.*;

/**
 * 表单 Service 实现类
 *
 * @author 数创万维
 */
@Service
@Validated
public class StepFormServiceImpl implements StepFormService {

    @Resource
    private StepFormMapper stepFormMapper;

    @Override
    public Long createStepForm(StepFormSaveReqVO createReqVO) {
        // 插入
        StepFormDO stepForm = BeanUtils.toBean(createReqVO, StepFormDO.class);
        stepFormMapper.insert(stepForm);
        // 返回
        return stepForm.getId();
    }

    @Override
    public void updateStepForm(StepFormSaveReqVO updateReqVO) {
        // 更新
        StepFormDO updateObj = BeanUtils.toBean(updateReqVO, StepFormDO.class);
        stepFormMapper.updateById(updateObj);
    }

    @Override
    public void deleteStepForm(Long id) {
        // 删除
        stepFormMapper.deleteById(id);
    }


    @Override
    public StepFormDO getStepForm(Long id) {
        return stepFormMapper.selectById(id);
    }

    @Override
    public StepFormDO getStepFormByStepId(Long stepId) {
        return stepFormMapper.selectOne(StepFormDO::getStepId, stepId);
    }

    @Override
    public PageResult<StepFormDO> getStepFormPage(StepFormPageReqVO pageReqVO) {
        return stepFormMapper.selectPage(pageReqVO);
    }

}